/*
 * Main.java
 *
 * Created on October 12, 2006, 10:25 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package edtest1;

import java.util.*;
import java.text.*;

/**
 *
 * @author plyryan
 */
public class Main {
    
    /** Creates a new instance of Main */
    public Main() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        long    start = System.currentTimeMillis();
        double  x = 0.0;
        int     detail = 40;
        int []  var = new int[detail];
        Random  ran = new Random ();
        int     total = 1024287;
        DecimalFormat   fmt = new DecimalFormat ("0.0000");
        DecimalFormat   fmt2 = new DecimalFormat ("0.0");
        
        for (int i = 0; i < total; i++) {
            x = ran.nextGaussian();
            for (float j = -4; j < 4; j+=(8.0/detail)) {
                if (x > j && x <= (j+(8.0/detail)))
                    var[(int)((j+4)*(detail/8.0))] += 1;
            }
        }
        
        System.out.print ("\n\n");
        System.out.println ("Random.nextGaussian () sample scaled 5.5x.");
        for (int i = 0; i < detail; i++) {
            //System.out.println (i-(detail/2.0) + ": " + var[i] + "  " + 
            //        fmt.format (((double)var[i] / (double)total)*100) + "%");
            System.out.print (fmt2.format(Math.abs(((double)i/(detail/8.0))-4)) + " ");
            for (int j = 0; j < (int)(((double)var[i] / (double)total)*550); j++) {
                System.out.print ("=");
            }
            System.out.println ();
        }
        System.out.println ();
        System.out.println (System.currentTimeMillis() - start + " ms\n");
        
        System.out.println ("The Gaussian formula scaled 1.0x.");
        for (double i = -4; i < 4; i+=(8.0/detail)) {
            System.out.print (fmt2.format (Math.abs (i)) + "  ");
            double end = (1.0 / Math.sqrt(2*Math.PI))*Math.pow (Math.E,(-0.5)*Math.pow((i), 2));
            //System.out.print (fmt.format (end));
            for (int j = 0; j < (int)(end*100); j++) {
                System.out.print ("=");
            }
            System.out.println ();
        }
    }
    
}
